package v1

import (
	"errors"
	"github.com/gin-gonic/gin"
	"jwgin/model/mysql"
	"jwgin/service"
)

//用户金豆变更
type recordBean struct {
}

func (l *recordBean) Routers(Router *gin.RouterGroup) {
	Router.GET("record/bean", l.get)
}

//获取所有列表
func (recordBean) get(c *gin.Context) {
	count, size, offset := pages(c)
	uid, b2ol := c.Get("UserID")
	if !b2ol {
		RespErr(c, errors.New("请重新登录"))
		return
	}
	db := service.G.Model(mysql.RecordBean{}).Where("uid = ?", uid)

	if tp := c.Query("type"); tp != "" {
		db = db.Where("type = ?", tp)
	}
	if orderid := c.Query("orderid"); orderid != "" {
		db = db.Where("orderid = ?", orderid)
	}

	//时间筛选
	startTime := c.Query("startTime")
	endTime := c.Query("endTime")
	if startTime != "" && endTime != "" {
		db = db.Where(" record_bean.addtime > ? AND record_bean.addtime < ? ", startTime, endTime)
	}

	list := []map[string]interface{}{}
	db.Count(&count).Offset(offset).Limit(size).Scan(&list)
	RespList(c, count, list)
}
